package com.doit.day01;


import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MapTask extends TableMapper<Text,Text>{

    @Override
    protected void map(ImmutableBytesWritable key, Result value, Mapper<ImmutableBytesWritable, Result, Text, Text>.Context context) throws IOException, InterruptedException {
        // 获取字符串的 rowkey
        String k = new Text(new String(key.copyBytes())).toString();
        //获取指定的属性的值
        String name = Bytes.toString(value.getValue("f".getBytes(), "name".getBytes()));
        String gender = Bytes.toString(value.getValue("f".getBytes(), "gender".getBytes()));
        System.out.println(k + "  " + name);
        // 以行建为key 以多个属性组装的结果为value传递 到reduce中
        context.write(new Text(k), new Text(name + ":" + gender));
    }
}